//
//  CYTicketDetailViewController.m
//  CaiYun
//
//  Created by 今日信息科技 on 2017/6/12.
//  Copyright © 2017年 今日信息科技. All rights reserved.
//

#import "CYTicketDetailViewController.h"
#import "CYTicketDetailHeaderView.h"
#import "CYTicketDetailMiddleView.h"
#import "CYTicketDetailFooderView.h"
#import "CYBettingViewController.h"
#import "CYLotteryDetailModel.h"
@interface CYTicketDetailViewController ()
@property (nonatomic, strong) CYTicketDetailHeaderView *headerView;//上部分视图
@property (nonatomic, strong) CYTicketDetailMiddleView *middleView;//中间部分视图
@property (nonatomic, strong) CYTicketDetailFooderView *fooderView;//下面部分视图
@property (nonatomic, strong) CYImageView *tipsIMG;//投注按钮上的小字
@property (nonatomic, strong) CYButton *bettingBtn;//投注按钮
@property (nonatomic, strong) CYLotteryDetailModel *model;
@end

@implementation CYTicketDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.headerView.hidden = self.middleView.hidden = self.fooderView.hidden = NO;
    self.bettingBtn.hidden = self.tipsIMG.hidden = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    
    // Do any additional setup after loading the view.
}


- (CYTicketDetailHeaderView *)headerView{
    if (!_headerView) {
        _headerView = [[CYTicketDetailHeaderView alloc]initWithColor:[UIColor whiteColor]];
        [self.view addSubview:_headerView];
        
        [_headerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.view).with.offset(NAVIBAR_HEIGHT + STATUS_HEIGHT);
            make.centerX.equalTo(self.view);
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, AUTO(120)));
        }];
    }
    return _headerView;
}

- (CYTicketDetailMiddleView *)middleView{
    if (!_middleView) {
        _middleView = [[CYTicketDetailMiddleView alloc]initWithColor:[UIColor whiteColor]];
        [self.view addSubview:_middleView];
        
        [_middleView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_headerView.mas_bottom).with.offset(0);
            make.centerX.equalTo(self.view);
            make.size.mas_equalTo(_middleView.bounds.size);
        }];
    }
    return _middleView;
}

- (CYTicketDetailFooderView *)fooderView{
    if (!_fooderView) {
        _fooderView  = [[CYTicketDetailFooderView alloc]initWithColor:[UIColor whiteColor]];
        [self.view addSubview:_fooderView];
        
        [_fooderView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_middleView.mas_bottom).with.offset(0);
            make.bottom.equalTo(self.view.mas_bottom).with.offset(0);
            make.centerX.equalTo(self.view);
            make.width.mas_equalTo(SCREEN_WIDTH);
        }];
    }
    return _fooderView;
}

- (CYButton *)bettingBtn{
    if (!_bettingBtn) {
        _bettingBtn = [[CYButton alloc]initWithImage:@"touzhuBtn" cornerRadius:0.0];
        [_bettingBtn addTarget:self action:@selector(touzhu) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:_bettingBtn];
        
        [_bettingBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self.view.mas_bottom).with.offset(- 60);
            make.centerX.equalTo(self.view);
            make.size.mas_equalTo(CGSizeMake(180.0, 42.0));
        }];
    }
    return _bettingBtn;
}

- (CYImageView *)tipsIMG{
    if (!_tipsIMG) {
        _tipsIMG = [[CYImageView alloc]initWithImage:[UIImage imageNamed:@"zi"]];
        [self.view addSubview:_tipsIMG];
        
        [_tipsIMG mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(_bettingBtn.mas_top).with.offset(-5);
            make.centerX.equalTo(self.view);
            make.size.mas_equalTo(CGSizeMake(135, 15));
        }];
    }
    return _tipsIMG;
}

- (void)setModel:(CYLotteryDetailModel *)model{
    if (_model != model) {
        _model = model;
        _headerView.name = _model.name;//彩种
        _headerView.action_num = _model.number;//期号
        _headerView.time = _model.time;//时间
        _headerView.number = _model.num;//每天中奖次数
        _headerView.results = [_model.data componentsSeparatedByString:@","];//中奖号码
        _middleView.money = _model.bet_bonus;//本期销量
        _middleView.peopleNum = _model.people;//参与人数
        _fooderView.totalMoney = _model.bonus;//累计奖金
    }
}

#pragma mark - 按钮事件
- (void)touzhu{
    CYBettingViewController *bettingVC  = [[CYBettingViewController alloc]init];
    bettingVC.lottery_id = _para[@"id"];
    bettingVC.lottery_name = _model.name;
    [self.navigationController pushViewController:bettingVC animated:YES];
}

- (void)https{
    
    self.task = [CYHttps POST:API_result_detailOnes parameters:_para showHUD:YES progress:nil success:^(id data) {
        self.model = [CYLotteryDetailModel mj_objectWithKeyValues:data];
    } failure:nil];
    
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self https];
}

- (void)setupNavigationBarTintColor:(UIColor *)color{
    [super setupNavigationBarTintColor:color];
    self.navigationItem.title = @"开奖详情";
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
